#This is some work for Topic 26 # # First input the matrix that has perfect independence matrix_perfect <- matrix( c( 24, 20, 12, 36, 30, 18, 30, 25, 15, 24, 20, 12), ncol=3, nrow=4, byrow=TRUE) matrix_perfect # Now, generate all the related tables source("../crosstab.R") crosstab( matrix_perfect ) # # Now, repeat the same thing, but change 1 value matrix_perfect <- matrix( c( 25, 20, 12, 36, 30, 18, 30, 25, 15, 24, 20, 12), ncol=3, nrow=4, byrow=TRUE) matrix_perfect # and get the new tables crosstab( matrix_perfect ) # rather than look at the small print in the View tabs row_percent # # Now let us look at the other data on the video matrix_other <- matrix( c( 26, 23, 13, 27, 40, 16, 35, 19, 10, 21, 13, 14), ncol=3, nrow=4, byrow=TRUE) matrix_other # and get the new tables crosstab( matrix_other ) # # And a quick look at the Chi-squared distribution # First verify the last attaained result pchisq( 11.77495, 6, lower.tail=FALSE) # Then find the value that has 5% of the area to # the right qchisq( 0.05, 6, lower.tail=FALSE) # # Finally, let us genetate a new matrix source("../gnrnd4.R") gnrnd4( key1=895863908, key2=75864894754 ) matrix_A # See if the rows and columns of this are independent, # that is the null hypothesis, versus that they are # not independent, that is the alternative hypothesis, # and do this test at the 0.05 level of significance. crosstab( matrix_A ) # # # This was such fun, let us generate a new matrix gnrnd4( key1=114863908, key2=75864894754 ) matrix_A crosstab( matrix_A )